#ifndef DATABUFFER_H
#define DATABUFFER_H
#include "StompedReality/Core.h"
namespace StompedReality
{
namespace Core
{
/*!
 * \author	Stefan Kazalski
 *
 * \brief	Data store
 *
 *    Stores data into a char*.<br>
 *    Provides getter and setter for values.
 */
class DLL_EXPORT DataBuffer
{
 private:

  char* m_Buffer;

 public:

  //! \brief	Constructor.
  DataBuffer ( int size );

  //! \brief	Destructor.
  ~DataBuffer( );

  //! \brief	Generic value getter.
  //!   Copies the value of type T into the data buffer starting at the offset.
  //!   Returns a value of type T starting to the offset in the data .
  //! \return	the value.
  template <class T>
  const T GetValue ( int offset );

  //! \brief	Generic value setter.
  //!   Copies the value of type T into the data buffer starting at the offset.
  //! \param	offset	the offset.
  //! \param	value	the value of type T.
  template <class T>
  void SetValue ( int offset, const T value );
};

template <class T>
const T DataBuffer::GetValue ( int offset )
{
  return *( T* ) ( this->m_Buffer + offset );
}

template <class T>
void DataBuffer::SetValue ( int offset, const T value )
{
  *( T* ) ( this->m_Buffer + offset ) = value;
}

#define BUFFER_GETTER( name, type, offset ) \
  type get ## name ( ) { return this->getValue<type>( offset ); \
  }
#define BUFFER_SETTER( name, type, offset ) \
  void set ## name ( type value ) { this->setValue<type>( offset, value ); }
#define BUFFER_GETTER_SETTER( name, type, offset ) \
  BUFFER_GETTER( name, type, offset ); \
  BUFFER_SETTER( name, type, offset );
}
}
#endif // DATABUFFER_H
